package study.cell_game.objects.textures;

import org.andengine.engine.Engine;
import org.andengine.opengl.texture.TextureOptions;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.andengine.opengl.texture.region.TextureRegion;
import org.andengine.ui.activity.BaseGameActivity;

/**
 * created to be 'almost' singleton; there should be always only one instance, hovewer it needs separate initialization - we dont want to keep using 
 * @author bherman
 *
 */
public class MainMenuTextures extends CommonTextures{
	
	/**
	 * serves initialization of the 'singleton'
	 * @param activity
	 * @param engine
	 */
	public static MainMenuTextures getInstance(final BaseGameActivity activity, final Engine engine){
		if(instance == null){
			instance = new MainMenuTextures(activity, engine);
		}
		return instance;
	}
	
	private static MainMenuTextures instance;
	
	/**
	 * can be called even if base game activity or/and engine arent available
	 * @return
	 */
	public static MainMenuTextures getInstance(){
		return instance;
	}
	
	private BitmapTextureAtlas textureAtlas;
	private TextureRegion newGameButtonTextureRegion;
	private TextureRegion loadGameButtonTextureRegion;
	private TextureRegion quitGameButtonTextureRegion;
	private TextureRegion settingsButtonTextureRegion;
	private TextureRegion fullRingButtonTextureRegion;
	private TextureRegion backgroundElementTextureRegion;
	
	private MainMenuTextures(final BaseGameActivity activity, final Engine engine) {
	    super(activity, engine);
		
		//create atlas
		this.textureAtlas = new BitmapTextureAtlas(engine.getTextureManager(), 2048, 2048,
	        TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		
		
		//add textures to it.
	    this.backgroundElementTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(
		        this.textureAtlas, activity, "gfx/Menu/MainMenuLayout.png", 0, 0);
		
	    //row of button textures
		this.fullRingButtonTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(
		        this.textureAtlas, activity, "gfx/OuterRings/FullRing.png", 0, 720);
		this.newGameButtonTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(
			    this.textureAtlas, activity, "gfx/Menu/NewGameCoreToken.png", 80, 720);
		this.loadGameButtonTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(
			    this.textureAtlas, activity, "gfx/Menu/LoadCoreToken.png", 160, 720);
		this.quitGameButtonTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(
			    this.textureAtlas, activity, "gfx/Menu/CloseGameCoreToken.png", 240, 720);
		this.settingsButtonTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(
			    this.textureAtlas, activity, "gfx/Menu/SettingsCoreToken.png", 320, 720);  
		
		engine.getTextureManager().loadTexture(textureAtlas);
	}

	public TextureRegion getNewGameButtonTextureRegion() {
		return newGameButtonTextureRegion;
	}

	public TextureRegion getLoadGameButtonTextureRegion() {
		return loadGameButtonTextureRegion;
	}

	public TextureRegion getQuitGameButtonTextureRegion() {
		return quitGameButtonTextureRegion;
	}

	public TextureRegion getSettingsButtonTextureRegion() {
		return settingsButtonTextureRegion;
	}

	public TextureRegion getFullRingButtonTextureRegion() {
		return fullRingButtonTextureRegion;
	}

	public TextureRegion getBackgroundElementTextureRegion() {
		return backgroundElementTextureRegion;
	}
	
	
}
